//
//  PayByBagViewController.m
//  XDCommonApp
//
//  Created by wanglong8889@126.com on 14-4-21.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "PayByBagViewController.h"
#import "XDHeader.h"
//#import "orderListViewController.h"
@interface PayByBagViewController ()

@end

@implementation PayByBagViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.titleLabel.text = @"支付宝支付";
//    [self.leftBtn setBackgroundImage:[UIImage imageNamed:@"pd_25_bai"] forState:UIControlStateNormal];
    

    
//    self.titleLabel.textColor = [UIColor whiteColor];
    UIWebView *malongWeb = [[UIWebView alloc] init];
    malongWeb.delegate = self;
    if (IOS7) {
        malongWeb.frame = CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height);
    }else{
        malongWeb.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    }
    [self.view addSubview:malongWeb];
    [malongWeb loadRequest:[NSURLRequest requestWithURL:self.webUrl]];
}


- (void)webViewDidFinishLoad:(UIWebView *)webView{
    
    NSString *webUrl = [NSString stringWithFormat:@"%@",[[webView request] URL]];
    
    BOOL isWeb = [webUrl rangeOfString:@"http://www.meike365.cn/return_back.php?"].location !=NSNotFound;
    BOOL isSucess = [webUrl rangeOfString:@"result=success"].location !=NSNotFound;
    
    
    if (isWeb) {
        if (isSucess) {
            [self performSelector:@selector(completeShop) withObject:nil afterDelay:0.0];
        }else{
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}




-(void)completeShop{
    [self.navigationController popToRootViewControllerAnimated:YES];
    [[XDTools appDelegate].tabBarController confirmSelectTabBar:1];
    [[XDTools appDelegate].tabBarController setSelectedIndex:1];

}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
